package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.constant.MessageConstant;
import com.itheima.dao.OrderSettingMapper;
import com.itheima.entity.Result;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @version V1.0
 * @author: ljx
 * @date: 2020/01/14 21:56
 * @description:
 */
@Service(interfaceClass = OrderSettingService.class)
public class OrderSettingServiceImpl implements OrderSettingService {

    @Autowired
    private OrderSettingMapper orderSettingMapper;

    @Override
    public Result findOrders(String month) {
        //month格式是2020-1，数据库中包含日，查询整月的，我们将其拼上自然月中最小日，和最大自然日然后到数据库中
        //进行区间查询
        String start = month + "-1";
        String end = month + "-31";
        List<OrderSetting> list = orderSettingMapper.findOrders(start, end);
        new Result(true, MessageConstant.QUERY_ORDER_SUCCESS);

        LinkedList<Map> returnList = new LinkedList<>();

        if (list.size() > 0) {
            for (OrderSetting order : list) {
                HashMap<String, Integer> map = new HashMap<>();
                map.put("number", order.getNumber());
                map.put("reservations", order.getReservations());
                map.put("month", order.getOrderDate().getMonth());
                map.put("date", order.getOrderDate().getDate());
                returnList.add(map);
            }
        }

        return new Result(true, MessageConstant.QUERY_ORDER_SUCCESS, returnList);

    }
}
